package com.ruoyi.zyx.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zyx.domain.ZyxFile;
import com.ruoyi.zyx.service.IZyxFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件Controller
 * 
 * @author lhs
 * @date 2021-07-06
 */
@RestController
@RequestMapping("/zyx/file")
public class ZyxFileController extends BaseController
{
    @Autowired
    private IZyxFileService zyxFileService;

    /**
     * 查询文件列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZyxFile zyxFile)
    {
        startPage();
        List<ZyxFile> list = zyxFileService.selectZyxFileList(zyxFile);
        return getDataTable(list);
    }

    /**
     * 导出文件列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:file:export')")
    @Log(title = "文件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZyxFile zyxFile)
    {
        List<ZyxFile> list = zyxFileService.selectZyxFileList(zyxFile);
        ExcelUtil<ZyxFile> util = new ExcelUtil<ZyxFile>(ZyxFile.class);
        return util.exportExcel(list, "文件数据");
    }

    /**
     * 获取文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Integer fileId)
    {
        return AjaxResult.success(zyxFileService.selectZyxFileById(fileId));
    }

    /**
     * 新增文件
     */
    @PreAuthorize("@ss.hasPermi('zyx:file:add')")
    @Log(title = "文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZyxFile zyxFile)
    {
        return toAjax(zyxFileService.insertZyxFile(zyxFile));
    }

    /**
     * 修改文件
     */
    @PreAuthorize("@ss.hasPermi('zyx:file:edit')")
    @Log(title = "文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZyxFile zyxFile)
    {
        return toAjax(zyxFileService.updateZyxFile(zyxFile));
    }

    /**
     * 删除文件
     */
    @PreAuthorize("@ss.hasPermi('zyx:file:remove')")
    @Log(title = "文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Integer[] fileIds)
    {
        return toAjax(zyxFileService.deleteZyxFileByIds(fileIds));
    }
}
